package com.senior.sendmessage.config;

import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Baijl
 * @version 0.0.1
 * @date 2021-11-21 10:37
 * @description TODO
 */
@Configuration
@RequiredArgsConstructor
public class WeChatMessageRouter {

    private final WxChatMessageHandler wxChatMessageHandler;


    @Bean
    public WxMpMessageRouter getRouter(WxMpService wxMpService) {
        WxMpMessageRouter router = new WxMpMessageRouter(wxMpService);
        // 文本事件处理
        router.rule().async(false).msgType(WxConsts.XmlMsgType.TEXT).handler(wxChatMessageHandler).end();
        return router;
    }
}
